//
//  DESingleton.h
//  DemoObjective-CWeb
//
//  Created by Mon on 15/12/13.
//  Copyright © 2015年 Mon. All rights reserved.
//

// 头文件,全局访问方法的定义
#define DESingleton_h(name) +(instancetype)shared##name


#if !__has_feature(objc_arc)  // 非ARC
#define DESingleton_m(name) \
+(instancetype)shared##name{ \
static id instance = nil;\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
instance = [[self alloc] init];\
});\
return instance;\
}\
\
+ (instancetype)allocWithZone:(struct _NSZone *)zone {\
static id instance = nil;\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
instance = [super allocWithZone:zone];\
});\
return instance;\
}\
\
- (id)copyWithZone:(nullable NSZone *)zone{\
return self;\
}\
- (oneway void)release {}\
\
- (instancetype)autorelease {\
return nil;\
}\
\
- (instancetype)retain {\
return self;\
}\
\
- (NSUInteger)retainCount {\
return 1;\
}


#else // ARC

#define DESingleton_m(name) \
+(instancetype)shared##name{ \
static id instance = nil;\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
instance = [[self alloc] init];\
});\
return instance;\
}\
\
+ (instancetype)allocWithZone:(struct _NSZone *)zone {\
static id instance = nil;\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
instance = [super allocWithZone:zone];\
});\
return instance;\
}\
\
- (id)copyWithZone:(nullable NSZone *)zone{\
return self;\
}

#endif